package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api
public class OrderController {
    @Autowired
    private OrderService orderService;


    @RequestMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> getAllOrders( OrdersPageQueryDTO ordersPageQueryDTO) {

                log.info("订单搜索");
        PageResult pageResult = orderService.orderList(ordersPageQueryDTO);

        return Result.success(pageResult);
    }
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> getOrderStatistics() {

      OrderStatisticsVO orderStatisticsVO =orderService.getOrderStatistics();

      return Result.success(orderStatisticsVO);
    }



    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirmOrder(@RequestBody Orders orders) {

            log.info("接单号:{}",orders.getId());
            orderService.confirmOrder(orders);

         return Result.success();
    }

    @PutMapping("/delivery/{orderId}")
    @ApiOperation("派送订单")
    public Result DeliveryingOrders(@PathVariable Long orderId) {

        log.info("派送订单:{}",orderId);

        orderService.DeliveryingOrders(orderId);


        return Result.success();
    }
    @GetMapping("/details/{orderId}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> getOrderDetails(@PathVariable Long orderId) {

        log.info("查询订单id为:{}的详情",orderId);
      OrderVO orderVO=  orderService.getOrderDetails(orderId);

         return Result.success(orderVO);
    }


    @PutMapping("/complete/{orderId}")
    @ApiOperation("完成订单")
    public Result completeOrder(@PathVariable Long orderId) {

            log.info("订单id:{}完成",orderId);
            orderService.completeOrder(orderId);

            return  Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody Orders orders) {

        log.info("取消订单id为:{}的订单",orders.getId());

        orderService.cancelOrder(orders);

        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result rejectOrder(@RequestBody Orders orders) {

        log.info("拒绝订单号为:{}的订单",orders.getId());

        orderService.rejecOrder(orders);


        return Result.success();
    }

}
